import pygame


class Mine(pygame.sprite.Sprite):
    def __init__(self, x, y, image):
        super(Mine, self).__init__()
        self.pos_x = x
        self.pos_y = y
        self.image = image
        (x, y, w, h) = self.image.get_rect()
        self.rect = pygame.Rect(self.pos_x, self.pos_y, w, h)

    def draw(self, current_surface, x, y):
        current_surface.blit(self.image,
                             (self.pos_x - x, self.pos_y - y))


class Boom(pygame.sprite.Sprite):
    def __init__(self, x, y, image, row, col):
        super(Boom, self).__init__()
        self.col = col
        self.row = row
        self.pos_x = x
        self.pos_y = y
        self.image = image
        (x, y, w, h) = self.image.get_rect()
        w = w / col
        h = h / row
        # 图片计数
        self.no = 0
        self.boom_image = []
        self.count = row * col
        # 分割图片 并把分割后的放入数组
        for i in range(0, self.count):
            temp_row = int(i / self.col)
            temp_col = i % self.col
            rect = (temp_col * w, temp_row * h, w, h)
            image = self.image.subsurface(rect)
            self.boom_image.append(image)
        # 延长显示计数
        self.show_count = 0

    def draw(self, current_surface, x, y):
        if self.no >= self.count - 1:
            return
        # 延长显示时间
        self.show_count += 1
        if self.show_count > 10:
            self.no += 1
            self.show_count = 0
            if self.no >= self.count:
                return
        current_surface.blit(self.boom_image[self.no],
                             (self.pos_x - x, self.pos_y - y))

    def kill_flag(self):
        """
        是否杀死精灵
        :return:
        """
        if self.no >= self.count:
            return True
        else:
            return False
